2.6 Population filtering
Filtering of datasets is done by using the drop
or keep
commands after you have first created a dataset using an import command:
import ds/BEFOLKNING_KJOENN as gender
drop if gender == '1'
In microdata.no, if-expressions may be used in many contexts. The following common logical operators are possible to use:
-
Larger than:
>
-
Less than:
<
-
Equal to:
==
-
Larger than or equal:
>=
-
Less than or equal:
<=
-
Not equal:
!=
-
Or:
|
-
And:
&
The following expression will remove individuals under 18 years from your population:
keep if age >= 18
Values for missing data can be assigned as follows:
sysmiss(<variable>)
Individuals with no data on wage income can be removed from your population as follows:
drop if sysmiss(wage)
It is also possible to create random samples from a dataset. The command sample
may be used for such purposes. For more about syntax and examples, use the command help sample
.